package com.demo.chapter8;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PeekDemo {

	public static void main(String[] args) {
		//peek可以打印内容，用于中间调试
		List<Integer> result = Stream.of(2, 3, 4, 5)
				.peek(x -> System.out.println("taking from stream: " + x))
				.map(x -> x + 17)
				.peek(x -> System.out.println("after map: " + x))
				.filter(x -> x % 2 == 0)
				.peek(x -> System.out.println("after filter: " + x)).limit(3)
				.peek(x -> System.out.println("after limit: " + x))
				.collect(Collectors.toList());
	}

}
